package com.handinfo.game;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.engine.net.BaseConnection;
import com.handinfo.engine.net.GameProtocol;
import com.handinfo.engine.resource.ResHead;
import com.handinfo.uimenu.window.UIAuctionList;
import com.handinfo.uimenu.window.UIAuctionSearch;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;

public class GameMessage
{
	public GameMessage()
	{

	}

	/** 是否锁定网络 */
	private boolean m_net_lock = false;

	private final int NET_LOCK_TIME = GameManager.FRAME_PER_SECOND * 120;// 实际时间
	private final int NET_LOCK_SHOW_TIME = NET_LOCK_TIME >> 1;// 显示时间
	private int m_net_lock_time = 0;

	public boolean lockNetwork()
	{
		if (m_net_lock) {
			Tools.debugPrintln("网络被锁定,无法发送信息!");
			return true;
		}
		else {
			m_net_lock = true;
			m_net_lock_time = 0;
			Tools.debugPrintln("发送信息完成,锁定网络!");
			return false;
		}
	}

	public boolean isNetLocked()
	{
		if (m_net_lock) {
			Tools.debugPrintln("网络被锁定,无法发送信息!");
			return true;
		}
		return false;
	}

	public void unlockNetwork()
	{
		m_net_lock = false;
		m_net_lock_time = 0;
		Tools.debugPrintln("接收信息,解锁网络!");
	}

	public boolean isLockNetwork()
	{
		return m_net_lock;
	}

	public boolean networkTimeLogic()
	{
		if (isLockNetwork()) {
			m_net_lock_time++;
			if (m_net_lock_time > NET_LOCK_TIME) {
				return true;
			}
		}
		return false;
	}

	public void drawNetworkTime(Graphics g)
	{
		if (isLockNetwork()) {
			if (m_net_lock_time > NET_LOCK_SHOW_TIME) {
				g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
				Tools.drawString(g, Tools.WHITE, Tools.BLACK, Integer.toString(m_net_lock_time / 10),
						(AbstractGameScreen.SCREEN_WIDTH >> 1),
						(AbstractGameScreen.SCREEN_HEIGHT >> 1) - (AbstractGameScreen.FONT_H >> 1), Tools.HCENTER_TOP);
			}
		}
	}

	public void drawNetworkIcon(Graphics g, Image img, int x, int y, int index)
	{
		int cx = g.getClipX();
		int cy = g.getClipY();
		int cw = g.getClipWidth();
		int ch = g.getClipHeight();
		g.setClip(x - (img.getWidth() >> 3), y - (img.getHeight() >> 1), img.getWidth() >> 2, img.getHeight());
		g.drawImage(img, x - (img.getWidth() >> 3) - index * (img.getWidth() >> 2), y - (img.getHeight() >> 1),
				Tools.LEFT_TOP);
		g.setClip(cx, cy, cw, ch);
	}

	// public void sendHeartBeat()
	// {
	// ByteArrayOutputStream baos = new ByteArrayOutputStream();
	// DataOutputStream dos = new DataOutputStream(baos);
	// try {
	// dos.writeLong(System.currentTimeMillis());
	// GameManager.getInstance().getConnection().sendMessage(BaseConnection2.DEST_GATEWAY,
	// 0, GameProtocol.CS_USER_REG, baos.toByteArray());
	// dos.close();
	// dos = null;
	// baos.close();
	// baos = null;
	// }
	// catch (IOException e) {
	// e.printStackTrace();
	// }
	// }

	/**
	 * 用户中心 - 第一次认证,指令号为101
	 *
	 * @param name
	 * 用户名
	 * @param password
	 * 密码
	 * @param version
	 * 版本号
	 */
	public void sendUserAuth(String name, String password, String version, long userID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(name);// String 登录名
			dos.writeUTF(password);// String 密码
			dos.writeUTF(version);// byte 版本号
			dos.writeLong(userID);
			dos.writeInt(Tools.CHANNEL);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_AUTH, baos.toByteArray());
			Tools.debugPrintln("发送第一次认证 : " + GameProtocol.CS_USER_AUTH + " : " + name + " : " + password + " : "
					+ version + " : " + Tools.CHANNEL);
			UserScreen.m_record_auth = GameProtocol.CS_USER_AUTH;
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 用户中心 - 重新认证,指令号为110
	 *
	 * @param name
	 * 用户名
	 * @param sessionID
	 * 会话ID
	 */
	public void sendUserReauth(String name, long sessionID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(name);// String 登录名
			dos.writeLong(sessionID);// long 会话ID
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_REAUTH, baos.toByteArray());
			UserScreen.m_record_auth = GameProtocol.CS_USER_REAUTH;
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取角色列表, 指令号为104
	 */
	public void sendUserActorList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_ROLE_LIST, baos.toByteArray());
			Tools.debugPrintln("发送获取角色列表 : " + GameProtocol.CS_USER_ROLE_LIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取服务器列表, 指令号为107
	 */
	public void sendUserServerList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_SERVER_LIST, baos.toByteArray());
			Tools.debugPrintln("发送获取服务器列表 : " + GameProtocol.CS_USER_SERVER_LIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 断开当前角色的其他连接
	 */
	public void sendUserDisconnectAnother()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_DISCONNECT_ANOTHER, baos.toByteArray());
			Tools.debugPrintln("发送断开其他连接 : " + GameProtocol.CS_USER_DISCONNECT_ANOTHER);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 创建角色 , 指令号为105
	 *
	 * @param alias
	 * 名字
	 * @param Gender
	 * 性别 SEX_ALL = 0, //任意性别 MALE = 1, //男 FEMALE = 2,//女
	 * @param Job
	 * 职业 JOB_ALL = 0, //任意职业 JIAN_KE = 1, //剑客 WU_ZHE = 2, //武者
	 * DAO_SHI = 3,//斗士 JIAN_XIA = 4,//剑侠 JIAN_HAO = 5,//剑豪
	 * MENG_JIANG = 6,//猛将 DOU_SHI = 7, //斗士 FANG_SHI = 8, //方士
	 * SHU_SHI = 9, //术士 JIAN_SHEN = 10,//剑神 JIAN_MO = 11, //剑魔
	 * JIAN_SHENG= 12, //剑圣 ZHAN_KUANG = 13,//战狂 TIAN_JIANG = 14,
	 * //天将 WU_SHENG = 15,//武圣 YAN_LUO = 16, //阎罗 TIAN_SHI = 17, //天师
	 * DAO_SHENG = 18, //道圣
	 * @param Race
	 * RACE_ALL = 0, //任意 GOD = 1, //仙 GOBLIN = 2, //妖 HUMAN = 3, //人
	 * GHOST = 4,//鬼
	 */
	public void sendUserCreateRole(String alias, byte Gender, byte Job, byte Race)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(alias);
			dos.writeByte(Gender);
			dos.writeByte(Job);
			dos.writeByte(Race);
			dos.writeInt(Tools.CHANNEL);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_CREATE_ROLE, baos.toByteArray());
			debugPrintRole(alias, Gender, Job, Race);
			Tools.debugPrintln("创建角色 : " + GameProtocol.CS_USER_CREATE_ROLE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void debugPrintRole(String name, byte gender, byte job, byte race)
	{
		String[] genders = { "男", "女" };
		String[] jobs = { "剑客", "武者", "道士" };
		String[] races = { "仙", "妖", "人", "鬼" };
		Tools.debugPrintln("玩家 : " + name + ", 性别 : " + genders[gender - 1] + ", 职业 : " + jobs[job - 1] + ", 种族 : "
				+ races[race - 1]);
	}

	/**
	 * 选择角色, 指令号为111
	 *
	 * @param roleID
	 * 角色ID
	 */
	public void sendUserSelectRole(long roleID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(roleID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_SELECT_ROLE, baos.toByteArray());
			Tools.debugPrintln("发送选择角色 : " + GameProtocol.CS_USER_SELECT_ROLE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 角色信息
	 *
	 * @param roleID
	 */
	public void sendUserInformation(long roleID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(roleID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_USER_INFORMATION,
					baos.toByteArray());
			Tools.debugPrintln("发送角色信息 : " + GameProtocol.CS_USER_INFORMATION);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 场景信息
	 *
	 * @param roleID
	 */
	public void sendSceneInformation(long roleID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(roleID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_INFORMATION,
					baos.toByteArray());
			Tools.debugPrintln("发送场景信息 : " + GameProtocol.CS_SCENE_INFORMATION);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 技能信息
	 *
	 * @param roleID
	 */
//	public void sendUserSkillInformation(long roleID) {
//		if (lockNetwork()) {
//			return;
//		}
//		ByteArrayOutputStream baos = new ByteArrayOutputStream();
//		DataOutputStream dos = new DataOutputStream(baos);
//		try {
//			dos.writeLong(roleID);
//			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_USER_SKILL_INFORMATION, baos.toByteArray());
//			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_USER_SKILL_INFORMATION);
//			dos.close();
//			dos = null;
//			baos.close();
//			baos = null;
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}


	/**
	 * 获取世界列表, 指令号为116
	 */
	public void sendUserWorldList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_WORLD_LIST, baos.toByteArray());
			Tools.debugPrintln("发送获取世界列表 : " + GameProtocol.CS_USER_WORLD_LIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 角色下线，指令号为2004
	 *
	 * @param actorID
	 * 角色ID
	 * @param userID
	 * 用户ID
	 */
	public void sendOffOnline(long actorID, long userID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(actorID);
			dos.writeLong(userID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_USER_OFFLINE, baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除角色， 指令号为119
	 *
	 * @param id
	 * 角色ID
	 */
	public void sendUserDeleteRole(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_DELETE_ROLE, baos.toByteArray());
			Tools.debugPrintln("发送删除角色 : " + GameProtocol.CS_USER_DELETE_ROLE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 取消删除角色， 指令号为121
	 *
	 * @param id
	 * 角色ID
	 */
	public void sendUserFindRole(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_FIND_ROLE, baos.toByteArray());
			Tools.debugPrintln("发送取消删除角色 : " + GameProtocol.CS_USER_FIND_ROLE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 注册账号
	 *
	 * @param userID
	 * 注册次数
	 * @param ID
	 * 用户账号
	 * @param password
	 * 用户密码
	 * @param IMEI
	 * 手机唯一码
	 * @param model
	 * 手机型号
	 * @param mobileNO
	 * 手机号码
	 */
	public void sendUserRegister(long userID, String ID, String password, String IMEI, String model, String mobileNO)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(userID);
			dos.writeUTF(ID);
			dos.writeUTF(password);
			dos.writeInt(Tools.CHANNEL);
			dos.writeUTF(IMEI);
			dos.writeUTF(model);
			dos.writeUTF(mobileNO);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_REGISTER, baos.toByteArray());
			Tools.debugPrintln("发送注册账号 : " + GameProtocol.CS_USER_REGISTER + ",userID : " + userID + ",Account : " + ID
					+ ",password : " + password + ",渠道ID : " + Tools.CHANNEL
					+ ",手机唯一码 : " + IMEI + ",手机型号 : " + model + ",手机号码 : " + mobileNO);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 自动注册
	 *
	 * @param userID
	 * @param 渠道ID
	 * @param IMEI
	 * 手机唯一码
	 * @param model
	 * 手机型号
	 * @param mobileNO
	 * 手机号码
	 */
	public void sendUserAutoRegister(long userID, String IMEI, String model, String mobileNO)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(userID);
			dos.writeInt(Tools.CHANNEL);
			dos.writeUTF(IMEI);
			dos.writeUTF(model);
			dos.writeUTF(mobileNO);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_AUTO_REGISTER, baos.toByteArray());

			Tools.debugPrintln("发送自动注册账号 : " + GameProtocol.CS_USER_AUTO_REGISTER + ",userID : " + userID + ",渠道ID : "
					+ Tools.CHANNEL + ",手机唯一码 : " + IMEI + ",手机型号 : " + model
					+ ",手机号码 : " + mobileNO);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送进入世界
	 *
	 * @param id
	 */
	public void sendUserSelectWorld(int id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_SELECT_WORLD, baos.toByteArray());
			Tools.debugPrintln("发送进入世界 : " + GameProtocol.CS_USER_SELECT_WORLD + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 修改密码
	 *
	 * @param account
	 * @param userID
	 * @param oldPassword
	 * @param newPassword
	 */
	public void sendUserChangePassword(String account, long userID, String oldPassword, String newPassword)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(account);
			dos.writeLong(userID);
			dos.writeUTF(oldPassword);
			dos.writeUTF(newPassword);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_CHANGE_PASSWORD, baos.toByteArray());
			Tools.debugPrintln("发送修改密码 : " + GameProtocol.CS_USER_CHANGE_PASSWORD + "!账号 : " + account + ",userID : "
					+ userID + ",旧密码: " + oldPassword + ",新密码: " + newPassword);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送绑定手机号码
	 *
	 * @param id
	 */
	public void sendUserBinding(String account, String password, String phone, String email)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(account);
			dos.writeUTF(password);
			dos.writeUTF(phone);
			dos.writeUTF(email);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_BINDING, baos.toByteArray());
			Tools.debugPrintln("发送账号绑定 : " + GameProtocol.CS_USER_BINDING + "!账号 : " + account + ",密码 : " + password
					+ ",手机 : " + phone + ",邮箱 : " + email);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送解除绑定手机号码
	 *
	 * @param id
	 */
	public void sendUserUnbind(String account, String password)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(account);
			dos.writeUTF(password);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_UNBIND, baos.toByteArray());
			Tools.debugPrintln("发送解除绑定 : " + GameProtocol.CS_USER_UNBIND + "!账号 : " + account + ",密码 : " + password);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送找回密码
	 *
	 * @param id
	 */
	public void sendUserRetrievePassword(String phone, String email)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(phone);
			dos.writeUTF(email);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_USER_RETRIEVE_PASSWORD, baos.toByteArray());
			Tools.debugPrintln("发送找回密码 : " + GameProtocol.CS_USER_RETRIEVE_PASSWORD + "!电话 : " + phone + ",邮箱 : "
					+ email);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送兑换
	 *
	 * @param key
	 */
	public void sendGiftBagExchange(String key)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GIFT_BAG_EXCHANGE,
					baos.toByteArray());
			Tools.debugPrintln("发送兑换礼包 : " + GameProtocol.CS_GIFT_BAG_EXCHANGE + " : " + key + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 角色移动, 指令号为3001
	 *
	 * @param point
	 * 拐点数量
	 * @param x
	 * 拐点x集合
	 * @param y
	 * 拐点y集合
	 * @param direct
	 * 拐点方向集合
	 */
	public void sendMove(int type, ArrayList point)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(type);
			dos.writeByte(point.size());
			for (int i = 0; i < point.size(); i++) {
				int info = ((Integer) (point.elementAt(i))).intValue();
				int x = info & 0x0000ffff;
				int y = (info >> 16) & 0x0000ffff;
				dos.writeShort(x);
				dos.writeShort(y);
			}
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_MOVE, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 切换场景, 指令号3003
	 *
	 * @param id
	 * NPC ID
	 */
	public void sendChange(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			Tools.debugPrintln("send change id -> " + id);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_CHANGE, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendChangeFinished()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_CHANGE_FINISHED,
					baos.toByteArray());
			Tools.debugPrintln("发送切换场景完成 : " + GameProtocol.CS_SCENE_CHANGE_FINISHED);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送战斗同屏更新
	 *
	 * @param targetID
	 * 目标ID
	 * @param targetType
	 * 目标类型
	 * @param actionCount
	 * 动作序列
	 * @param ationID
	 * 动作ID列表
	 */
	public void sendBattleUpdate(int targetID, int targetType, int actionID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(targetID);
			dos.writeByte(targetType);
			dos.writeInt(actionID);
			Tools.debugPrintln("send battle -> " + targetID + " : " + targetType + " : " + actionID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_BATTLE_UPDATE,
					baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// /////////////////////////////////
	// x 组队
	// /////////////////////////////////
	/**
	 * 请求组队,邀请组队
	 *
	 * @param type
	 * 交互类型
	 * @param targetID
	 * 目标ID
	 */
	public void sendTeamRequest(long targetID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
//			if (GameManager.getInstance().m_role.m_teamID != 0) {
//				Vector vec = GameManager.getInstance().m_role.m_roleTeam;
//				for (int i = 0; i < vec.size(); i++) {
//					ActorRole role = (ActorRole) vec.elementAt(i);
//					if (role.m_gameID == targetID) {
//						return;
//					}
//				}
//			}
			dos.writeLong(targetID);
			Tools.debugPrintln("send request team -> " + targetID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_REQUESTTEAM, baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 是否同意组队
	 *
	 * @param type
	 * //0：申请加入队伍1：邀请加入队伍
	 * @param targetID
	 * @param operateType
	 */
	public void sendisAgree(byte type, long targetID, byte operateType)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(type);
			dos.writeByte(operateType);
			Tools.debugPrintln("send isAgree team -> " + operateType);
			dos.writeLong(targetID);
			Tools.debugPrintln("send isAgree team -角色ID> " + targetID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_ACCEPTTEAM, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 退出组队 空指令
	 */
	public void sendQuitTeam()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {

			Tools.debugPrintln("send quit team -> ");
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_QUITTEAM, baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 队长操作 （转让队长，踢出队员，解散队伍）
	 *
	 * @param type
	 * @param targetID
	 */
	public void sendLeaderHandle(byte type, long targetID, String name)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(targetID);
			dos.writeUTF(name);
			Tools.debugPrintln("send  leader handle-> " + type + " : " + targetID);

			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_LEADERHANDLE, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;

		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看附近队伍
	 */
	public void sendTeamNear()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			Tools.debugPrintln("send teamNear-->");
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_TEAMNEAR, baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 自动组队
	 *
	 */
	public void sendTeamAutoCreate()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			Tools.debugPrintln("send teamAutoCreate-->");
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_TEAMAUTOCREATE, baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 申请加入队伍
	 */
	public void sendTeamJoin(long teamID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			if (GameManager.getInstance().m_role.m_teamID != 0) {
				return;
			}
			dos.writeLong(teamID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_APPLYJOIN, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看队伍信息
	 *
	 * @param type
	 */
	public void sendTeamAllMsg()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			// long teamID=GameManager.getInstance().m_role.m_teamID;
			// dos.writeLong(teamID);
			// Tools.debugPrintln("查看队伍信息" + teamID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_TEAMALLMSG, baos.toByteArray());
			Tools.debugPrintln("发送队伍列表请求 : " + GameProtocol.CS_TEAM_TEAMALLMSG);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 跟随队长
	 *
	 * @param type
	 * 跟随类型
	 * @param targetID
	 * 目标ID
	 */
	public void sendFollowLeader(byte type, int targetID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeInt(targetID);
			Tools.debugPrintln("send follow leader -> " + type + " : " + targetID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_TEAM_FOLLOWLEADER,
					baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 登入时 获得队伍信息
	 *
	 * @param teamID
	 */
	public void sendTeamFristLogin(long teamID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(teamID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_TEAM_FIRSTLOGIN, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// //////////////////////////////////////////////////////////////////////
	/**
	 * 开始上坐骑
	 *
	 * @param RideId
	 */
	public void sendRideStart(long RideId)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(RideId);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_RIDE_STARTRIDE, baos.toByteArray());
			Tools.debugPrintln("发送上坐骑请求 : " + GameProtocol.CS_RIDE_STARTRIDE + " : " + RideId);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送完成上坐骑
	 */
	public void sendRideOver()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_RIDE_OVERRIDE, baos.toByteArray());
			Tools.debugPrintln("发送完成上坐骑 : " + GameProtocol.CS_RIDE_OVERRIDE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送下坐骑
	 */
	public void sendRideClose()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_RIDE_CLOSERIDE, baos.toByteArray());
			Tools.debugPrintln("发送下坐骑 : " + GameProtocol.CS_RIDE_CLOSERIDE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// ///////////////////////////////////////////////////////////////////
	/**
	 * 仇敌列表
	 */
	public void sendEnemyList(short page, short line)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(page);
			dos.writeShort(line);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_ENEMY_ENEMYLIST, baos.toByteArray());
			Tools.debugPrintln("发送仇敌列表请求 : " + GameProtocol.CS_SOCIAL_ENEMY_ENEMYLIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 仇敌详细信息请求
	 *
	 * @param EnemyID
	 * @param EnemyName
	 */
	public void sendEnemyInfo(long EnemyID, String EnemyName)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(EnemyID);
			dos.writeUTF(EnemyName);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_ENEMY_ENEMYINFO, baos.toByteArray());
			Tools.debugPrintln("发送仇敌详细信息请求 : " + GameProtocol.CS_SOCIAL_ENEMY_ENEMYINFO);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 仇敌具体位置请求
	 *
	 * @param EnemyID
	 */
	public void sendEnemyPosition(long EnemyID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(EnemyID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_ENEMY_QUERY_POSITION, baos.toByteArray());
			Tools.debugPrintln("发送仇敌具体位置请求 : " + GameProtocol.CS_SOCIAL_ENEMY_QUERY_POSITION);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除仇敌请求
	 *
	 * @param EnemyID
	 */
	public void sendEnemyDelete(long EnemyID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(EnemyID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_ENEMY_DELETE, baos.toByteArray());
			Tools.debugPrintln("发送删除仇敌请求 : " + GameProtocol.CS_SOCIAL_ENEMY_DELETE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发布通缉令
	 *
	 * @param EnemyID
	 * @param EnemyName
	 * @param moneyAward
	 * @param moneyAwardNum
	 * @param msg
	 */
	public void sendEnemyWanted(long EnemyID, String EnemyName, byte moneyAwardState, long moneyAwardNum, String msg)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(EnemyID);
			dos.writeUTF(EnemyName);
			dos.writeByte(moneyAwardState);
			dos.writeLong(moneyAwardNum);
			dos.writeUTF(msg);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_WORLD, 0,
					GameProtocol.CS_SOCIAL_ENEMY_WANTED_POSTER, baos.toByteArray());
			Tools.debugPrintln("发布通缉令请求 : " + GameProtocol.CS_SOCIAL_ENEMY_WANTED_POSTER);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 锁定仇敌
	 *
	 * @param EnemyID
	 */
	public void sendEnemyLock(long EnemyID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(EnemyID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_ENEMY_LOCK, baos.toByteArray());
			Tools.debugPrintln("发送锁定仇敌请求 : " + GameProtocol.CS_SOCIAL_ENEMY_LOCK);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// //////////////////////////////////////////////////////////////////
	/**
	 * 发送列表请求
	 *
	 * @param type
	 */
	public void sendSocialList(byte type, int page, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeInt(page);
			dos.writeInt(num);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_LIST, baos.toByteArray());
			Tools.debugPrintln("发送社交列表请求 : " + GameProtocol.CS_SOCIAL_LIST + " : " + type);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送添加玩家
	 *
	 * @param type
	 * @param m_id_int
	 */
	public void sendSocialAdd(byte type, long id, String name)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(id);
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_ID_ADD, baos.toByteArray());
			Tools.debugPrintln("发送添加玩家类型 : " + type + ", ID : " + id + ", name : " + name + ", 指令号 : "
					+ GameProtocol.CS_SOCIAL_ID_ADD);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送添加玩家
	 *
	 * @param type
	 * @param m_id_int
	 */
	public void sendSocialAddForName(byte type, String name)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_NAME_ADD, baos.toByteArray());
			Tools.debugPrintln("发送添加玩家类型 : " + type + ", name : " + name + ", 指令号 : " + GameProtocol.CS_SOCIAL_NAME_ADD);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送删除玩家
	 *
	 * @param type
	 * @param id
	 */
	public void sendSocialDelete(byte type, long id)
	{

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_DELETE, baos.toByteArray());
			Tools.debugPrintln("发送删除玩家 : " + type + " , " + id);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 添加好友确认信息
	 *
	 * @param result
	 * @param id
	 */
	public void sendSocialConfirmation(byte result, long id)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(result);
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_SOCIAL_CONFIRMATION, baos.toByteArray());
			Tools.debugPrintln("发送添加好友确认信息 : " + result + " , " + id);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 进入洞府40002
	 *
	 * @param playerId
	 * 洞府所属玩家Id
	 */
	public void sendDongFuInto(long playerId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(playerId);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_INTO_DONGFU, baos.toByteArray());
			Tools.debugPrintln("进入洞府 : " + GameProtocol.CS_DONGFU_INTO_DONGFU);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 退出洞府
	 */
	public void sendDongFuOut()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DONGFU_OUT_DONGFU,
					baos.toByteArray());
			Tools.debugPrintln("退出洞府 : " + GameProtocol.CS_DONGFU_OUT_DONGFU);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 收获生产的道具
	 *
	 * @param propType
	 * 工具类型
	 */
	public void sendDongFuReap(byte toolType, String key, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(toolType);
			dos.writeUTF(key);
			dos.writeInt(num);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DONGFU_REAP_DONGFU,
					baos.toByteArray());
			Tools.debugPrintln("收获生产的道具 : " + GameProtocol.CS_DONGFU_REAP_DONGFU + "工具类型：" + toolType);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 得到将要生产的道具信息
	 *
	 * @param toolType
	 * 工具类型
	 * @param mapKey
	 * 地图KEy
	 */
	public void sendDongFuGetPropMsg(String mapKey)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(mapKey);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DONGFU_getPropMsg,
					baos.toByteArray());
			Tools.debugPrintln("得到将要生产的道具信息: " + GameProtocol.CS_DONGFU_getPropMsg + "地图Key" + mapKey);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 开始生产
	 *
	 * @param toolType
	 * 工具类型
	 * @param mapKey
	 * 地图KEy
	 */
	public void sendDongFuStartProduction(byte toolType, String mapKey, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(toolType);
			dos.writeUTF(mapKey);
			dos.writeInt(num);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DONGFU_START_PRODUCTION,
					baos.toByteArray());
			Tools.debugPrintln("开始生产: " + GameProtocol.CS_DONGFU_START_PRODUCTION + "工具类型：" + toolType + "地图Key"
					+ mapKey);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 加速道具
	 *
	 * @param GUID
	 */
	public void sendDongFuADDSpeed(long GUID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(GUID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DONGFU_ADD_SPEED,
					baos.toByteArray());
			Tools.debugPrintln("加速: " + GameProtocol.CS_DONGFU_ADD_SPEED + "加速道具id" + GUID);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/***
	 * 浇灌 40008
	 *
	 * @param id
	 */
	public void sendwatering(byte state, long id)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(state); // 状态
			dos.writeLong(id); // 状态为1洞府的ID，状态为2玩家的ID
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_WATERING, baos.toByteArray());
			Tools.debugPrintln("发送浇灌指令  ：" + GameProtocol.CS_DONGFU_WATERING);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看浇水人信息
	 *
	 * @param id
	 */
	public void sendDongFuWateringPlayerMsg(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeLong(id); // 洞府所有者的ID
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_LOOKMSG, baos.toByteArray());
			Tools.debugPrintln("发送查看澆水人信息指令  ：" + GameProtocol.CS_DONGFU_LOOKMSG);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 攻伐
	 *
	 * @param id
	 * @param name
	 */
	public void sendDongFuGongFa(long id, String name)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeLong(id); // 玩家的ID
			dos.writeUTF(name);//
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_GONGFA, baos.toByteArray());
			Tools.debugPrintln("发送攻伐 ：" + GameProtocol.CS_DONGFU_GONGFA);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看洞府被攻伐记录
	 *
	 * @param id
	 * 洞府id
	 */
	public void sendDongFuGongFAMSG(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeLong(id); // 洞府的ID
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_GONGFA_MSG, baos.toByteArray());
			Tools.debugPrintln("发送攻伐 记录：" + GameProtocol.CS_DONGFU_GONGFA_MSG);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获得攻伐列表
	 *
	 * @param page
	 * @param pageNum
	 */
	public void sendDongFuGongFaList(int page, int pageNum)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeInt(page);
			dos.writeInt(pageNum);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_GONGFALIST, baos.toByteArray());
			Tools.debugPrintln("发送攻伐 列表请求：" + GameProtocol.CS_DONGFU_GONGFALIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 洞府加速付费请求
	 *
	 * @param page
	 * @param pageNum
	 */
	public void sendDongFuSpeed(byte status)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(status);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_SPEED_ASK, baos.toByteArray());
			Tools.debugPrintln("发送洞府加速付钱：" + GameProtocol.CS_DONGFU_SPEED_ASK);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 洞府加速付费确认
	 *
	 * @param page
	 * @param pageNum
	 */
	public void sendDongFuSpeedUPYUANBAO(byte status)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(status);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_DONGFU_SPEEDUP_YUANBAO, baos.toByteArray());
			Tools.debugPrintln("发送洞府加速付钱确认：" + GameProtocol.CS_DONGFU_SPEEDUP_YUANBAO);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看NPC任务详细内容
	 *
	 * @param id
	 */
	public void sendNPCTaskView(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeUTF(key);// 任务id
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_TASK_NPC_VIEW, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_TASK_NPC_VIEW + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看玩家任务详细内容
	 *
	 * @param id
	 */
	public void sendRoleTaskView(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeUTF(key);// 任务id
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_TASK_ROLE_VIEW, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_TASK_ROLE_VIEW + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 完成任务
	 *
	 * @param id
	 */
	public void sendTaskFinish(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeUTF(key);// 任务id
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_TASK_FINISH, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_TASK_FINISH + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 接受任务发送
	 *
	 * @param id
	 */
	public void sendTaskBegin(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);// 任务id
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_TASK_BEGIN, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_TASK_BEGIN + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 放弃任务发送
	 *
	 * @param id
	 */
	public void sendTaskAbort(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);// 任务id
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_TASK_ABORT, baos.toByteArray());
			Tools.debugPrintln("发送8004信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看玩家任务列表
	 */
	public void sendTaskRoleList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_TASK_ROLE_LIST, baos.toByteArray());
			Tools.debugPrintln("发送8100信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送功能选项
	 *
	 * @param function
	 * 功能指令
	 * @param id
	 * 功能ID
	 */
	public void sendFunction(int function, String id)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(id);// 功能附带数据ID
			GameManager.getInstance().getConnection().sendMessage(0, function, baos.toByteArray());
			Tools.debugPrintln("发送" + function + "信息 Data ID : " + id);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送复活功能选项
	 *
	 * @param id
	 * 功能ID
	 */
	public void sendReviveFunction(int function)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, function, baos.toByteArray());
			Tools.debugPrintln("发送" + function + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送同意复活
	 *
	 * @param function
	 * 功能指令
	 * @param id
	 * 功能ID
	 */
	public void sendReviveAgree()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_REVIVE_AGREE, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_REVIVE_AGREE + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送查看生活技能详细信息
	 *
	 * @param id
	 */
	public void sendLifeSkillsView(byte type, String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_VIEW,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_VIEW + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送学习生活技能
	 *
	 * @param id
	 */
	public void sendLifeSkillsStudy(byte type, String key, long NPCID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeUTF(key);
			dos.writeLong(NPCID);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_STUDY,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_STUDY + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送遗忘生活技能
	 *
	 * @param type
	 */
	public void sendLifeSkillsForget(byte type)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);// 技能类型
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_FORGET,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_FORGET + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送进入洞府指令
	 *
	 * @param id
	 * 洞府玩家ID
	 */
	public void sendLifeSkillsCavesInto(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);// 玩家ID
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_INTO,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_INTO + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送退出洞府指令
	 *
	 * @param id
	 * 洞府玩家ID
	 */
	public void sendLifeSkillsCavesQuit()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_QUIT,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_QUIT + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送取消生产指令
	 *
	 * @param id
	 * 生产技能ID
	 */
	public void sendLifeSkillsCavesCancel(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);// 生产技能ID
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_CANCEL,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_CANCEL + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送收获生产指令
	 *
	 * @param id
	 * 生产技能ID
	 */
	public void sendLifeSkillsCavesHarvest(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);// 生产技能key
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_HARVEST,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_HARVEST + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 已学生活技能列表请求
	 *
	 * @param location
	 * 位置
	 */
	public void sendLifeSkillsCavesKnow(byte location)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(location);// 生产的位置 左还是右
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_KNOW,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_KNOW + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 使用生活技能指令
	 *
	 * @param type
	 * @param key
	 */
	public void sendLifeSkillsCavesProdu(byte type, String key, int amount)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);// 类型
			dos.writeUTF(key);// 技能KEY
			dos.writeInt(amount);// 组数
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_PRODU,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_PRODU + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 选择生活技能指令
	 *
	 * @param type
	 * @param key
	 */
	public void sendLifeSkillsCavesSelect(byte type, String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);// 类型
			dos.writeUTF(key);// 技能KEY
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_SELECT,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_SELECT + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看自己洞府状态
	 *
	 * @param type
	 * @param key
	 */
	public void sendLifeSkillsCavesSelfStatus(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);// 类型
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LIFE_SKILLS_CAVES_SELF_STATUS,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_LIFE_SKILLS_CAVES_SELF_STATUS + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 选择NPC
	 *
	 * @param npcId
	 * NPC的id
	 */
	public void sendNPCList(long npcId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			Tools.debugPrintln("发送NPC列表请求!" + npcId);
			dos.writeLong(npcId);// 定义当前NpcId
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_NPC_LIST, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送与NPC互动结束
	 */
	public void sendNPCInteractEnd(byte type)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_NPC_INTERACT_END,
					baos.toByteArray());
			Tools.debugPrintln("发送NPC互动结束" + GameProtocol.CS_NPC_INTERACT_END + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送寻路指令
	 *
	 * @param String
	 * key
	 */
	public void sendScenePathfinding(String key)
	{
		if (lockNetwork()) {
			return;
		}
		if(GameManager.getInstance().m_role != null){
			GameManager.getInstance().m_role.stopAutoHangUp();
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_PATHFINDING,
					baos.toByteArray());
			Tools.debugPrintln("发送寻路指令" + GameProtocol.CS_SCENE_PATHFINDING + "! key : " + key);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送直接传送指令
	 *
	 * @param String
	 *            key
	 */
	public void sendDelivery(String key) {
//		if (lockNetwork()) {
//			return;
//		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_DELIVERY, baos.toByteArray());
			Tools.debugPrintln("发送直接传送指令" + GameProtocol.CS_SCENE_DELIVERY + "! key : " + key);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送场景地图指令
	 */
	public void sendSceneMap()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCENE_MAP, baos.toByteArray());
			Tools.debugPrintln("发送场景地图指令" + GameProtocol.CS_SCENE_MAP + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 同屏更新请求缺失NPC
	 *
	 * @param id
	 * @param type
	 */
	public void sendSceneUpdateDeficiency(ArrayList list)
	{

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			if (list != null) {
				dos.writeShort(list.size());
				for (int i = 0; i < list.size(); i++) {
					AbstractGameActor actor = (AbstractGameActor) list.elementAt(i);
					dos.writeLong(actor.m_gameID);
					dos.writeByte(actor.m_type);
					Tools.debugPrintln("请求NPC ID : " + actor.m_gameID);
				}
			}
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.SC_SCENE_UPDATE_DEFICIENCY,
					baos.toByteArray());
			Tools.debugPrintln("发送NPC缺失" + GameProtocol.SC_SCENE_UPDATE_DEFICIENCY + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// ////////////////////////////家族///////////////////////////////
	/**
	 * 验证是否可以创建家族
	 */
	public void sendFamilyVerify()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FAMILY_VERIFY, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_VERIFY);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 创建家族
	 *
	 * @param name
	 */
	public void sendFamilyCreate(String name)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FAMILY_CREATE, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_CREATE + " : " + name);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 家族列表
	 *
	 * @param page
	 * 当前页
	 * @param amount
	 * 每页显示数量
	 */
	// public void sendFamilyList(short page, short amount)
	// {
	// if (lockNetwork()) {
	// return;
	// }
	// ByteArrayOutputStream baos = new ByteArrayOutputStream();
	// DataOutputStream dos = new DataOutputStream(baos);
	// try {
	// dos.writeShort(page);
	// dos.writeShort(amount);
	// GameManager.getInstance().getConnection().sendMessage(
	// BaseConnection.DEST_UNIVERSE, 0, GameProtocol.CS_FAMILY_LIST,
	// baos.toByteArray());
	// Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_LIST + " : " +
	// amount);
	// dos.close();
	// dos = null;
	// baos.close();
	// baos = null;
	// }
	// catch (IOException e) {
	// e.printStackTrace();
	// }
	// }

	/**
	 * 申请加入家族
	 *
	 * @param id
	 */
	public void sendFamilyApplyAdd(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_APPLY_ADD, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_APPLY_ADD);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 通过家族名字加入家族
	 *
	 * @param id
	 */
	public void sendFamilyApplyAddName(String name)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_APPLY_ADD_NAME, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_APPLY_ADD_NAME);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 批准加入家族或者合并家族
	 *
	 * @param id
	 */
	public void sendFamilyRatifyAdd(byte type, long id, byte result)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(id);
			dos.writeByte(result);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_RATIFY_ADD, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_RATIFY_ADD);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看他人家族信息
	 */
	public void sendFamilyOtherMessage(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_OTHER_MESSAGE, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_OTHER_MESSAGE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送查看自己家族信息
	 */
	public void sendFamilyOwnMessage()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_OWN_MESSAGE, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_OWN_MESSAGE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 修改家族宣言
	 *
	 * @param text
	 */
	public void sendFamilyModifyManifesto(String text)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(text);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_MODIFY_MANIFESTO, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_MODIFY_MANIFESTO);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 修改家族公告
	 *
	 * @param text
	 */
	public void sendFamilyModifyNotice(String text)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(text);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_MODIFY_NOTICE, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_MODIFY_NOTICE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看家族申请列表
	 *
	 * @param page
	 * @param amountPage
	 * 每页 总数
	 */
	public void sendFamilyApplyList(short page, short amountPage)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(page);
			dos.writeShort(amountPage);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_APPLY_LIST, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_APPLY_LIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看家族成员列表
	 *
	 * @param page
	 * @param amountPage
	 * 每页总数
	 */
	public void sendFamilyMemberList(short page, short amountPage)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(page);
			dos.writeShort(amountPage);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_MEMBER_LIST, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_MEMBER_LIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 通过名字邀请加入家族
	 *
	 * @param name
	 */
	public void sendFamilyInviteAddName(String name)
	{

		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_INVITE_ADD_NAME, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_INVITE_ADD_NAME);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 通过ID邀请加入家族
	 *
	 * @param name
	 */
	public void sendFamilyInviteAddID(long ID)
	{

		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(ID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_INVITE_ADD_ID, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_INVITE_ADD_ID);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// /**
	// * 申请离开家族
	// */
	// public void sendFamilyApplyLeave() {
	// if (lockNetwork()) {
	// return;
	// }
	// ByteArrayOutputStream baos = new ByteArrayOutputStream();
	// DataOutputStream dos = new DataOutputStream(baos);
	// try {
	// GameManager.getInstance().getConnection().sendMessage(
	// BaseConnection.DEST_UNIVERSE, 0, GameProtocol.CS_FAMILY_APPLY_LEAVE,
	// baos.toByteArray());
	// Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_APPLY_LEAVE);
	// dos.close();
	// dos = null;
	// baos.close();
	// baos = null;
	// } catch (IOException e) {
	// e.printStackTrace();
	// }
	// }
	/**
	 * 确认离开家族
	 */
	public void sendFamilyConfirmLeave()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_CONFIRM_LEAVE, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_CONFIRM_LEAVE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送开除成员
	 */
	public void sendFamilyExpel(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_EXPEL, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_EXPEL);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送解散家族
	 */
	public void sendFamilyDismiss()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_DISMISS, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_DISMISS);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送取消解散家族
	 */
	public void sendFamilyCancelDismiss()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_CANCEL_DISMISS, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_CANCEL_DISMISS);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送确认被邀请入族
	 *
	 * @param confirm
	 * @param inviteID
	 * @param familyID
	 */
	public void sendFamilyInviteeAdd(byte confirm, long inviteID, long familyID)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(confirm);
			dos.writeLong(inviteID);
			dos.writeLong(familyID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_INVITEE_ADD, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_INVITEE_ADD + " : " + confirm);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 设置长老
	 *
	 * @param type
	 * 类型0提升, 1免职
	 * @param memberID
	 * 玩家ID
	 */
	public void sendFamilySetElder(byte type, long memberID)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(memberID);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_SET_ELDER, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_SET_ELDER + " : " + type + " : " + memberID);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 禅让族长
	 *
	 * @param id
	 * 成员ID
	 */
	public void sendFamilyDemiseSheikh(long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_DEMISE_SHEIKH, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_DEMISE_SHEIKH + " : " + id);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 申请合并家族
	 *
	 * @param familyName
	 */
	public void sendFamilyApplyMerge(String familyName)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(familyName);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FAMILY_APPLY_MERGE,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_APPLY_MERGE + " : " + familyName);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 家族捐献物资
	 *
	 * @param keys
	 * @param amount
	 */
	public void sendFamilyDonate(short amount, String[] keys, int[] num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(amount);
			for (int i = 0; i < amount; i++) {
				dos.writeUTF(keys[i]);
				dos.writeInt(num[i]);
				Tools.debugPrintln("捐献物资第" + i + "个key : " + keys[i] + ", num : " + num[i]);
			}
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FAMILY_DONATE, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_DONATE + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 家族抽奖开启
	 *
	 * @param keys
	 * @param amount
	 */
	public void sendFamilyLuckyOpen()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_FAMILY_LUCKY_OPEN, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_LUCKY_OPEN + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 家族抽奖获取结果
	 *
	 * @param keys
	 * @param amount
	 */
	public void sendFamilyLuckyResult()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FAMILY_LUCKY_RESULT,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FAMILY_LUCKY_RESULT + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送世界地图切换
	 *
	 * @param keys
	 * @param amount
	 */
	public void sendSceneTransfer(String key)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_SCENE_TRANSFER, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_SCENE_TRANSFER + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// ////////////////////////////战场///////////////////////////////
	/**
	 * 发送加入战场队列
	 *
	 * @param key
	 * @param type
	 * @param id
	 */
	public void sendBattlefieldJoinQueue(String key, byte type, long id)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			dos.writeByte(type);
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_INS, 0,
					GameProtocol.CS_BATTLEFIELD_JOIN_QUEUE_ASSIGN, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_BATTLEFIELD_JOIN_QUEUE_ASSIGN + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 进入战场
	 */
	public void sendBattlefieldInto()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_INS, 0,
					GameProtocol.CS_BATTLEFIELD_INTO, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_BATTLEFIELD_INTO + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 离开战场
	 */
	public void sendBattlefieldExit()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_INS, 0,
					GameProtocol.CS_BATTLEFIELD_EXIT, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_BATTLEFIELD_EXIT + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// ////////////////////////////战场///////////////////////////////
	/**
	 * 开启副本界面
	 */
	public void sendGameCarbonOpen()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAMECARBON_OPEN,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GAMECARBON_OPEN + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 副本自动组队
	 */
	public void sendGameCarbonAuto(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAMECARBON_AUTO,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GAMECARBON_AUTO + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 立即进入副本
	 */
	public void sendGameCarbonInto(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAMECARBON_INTO,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GAMECARBON_INTO + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 检测进入副本资格
	 */
	public void sendGameCarbonCheck(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAMECARBON_CHECK,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GAMECARBON_CHECK + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 取消副本自动组队
	 */
	public void sendGameCarbonExit(String key)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAMECARBON_EXIT,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GAMECARBON_EXIT + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 增加副本次数
	 */
	public void sendGameCarbonAdd(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_GAMECARBON_ADD, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_GAMECARBON_ADD + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// ////////////////////////////切磋///////////////////////////////
	/**
	 * 发送请求决斗
	 *
	 * @param id
	 */
	public void sendDuelRequest(long id)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DUEL_REQUEST, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_DUEL_REQUEST + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送回复是否同意决斗
	 *
	 * @param id
	 * @param result 0拒绝 1同意
	 */
	public void sendDuelConfirmation(long id, byte result)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			dos.writeByte(result);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DUEL_CONFIRMATION,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_DUEL_CONFIRMATION + "!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// //////////////////////////////////////////////////////////////
	// 曾光伟
	// //////////////////////////////////////////////////////////////

	/***************************************
	 * 气泡
	 ***************************************/
	/**
	 * 当前完成气泡对话需想服务器发送当前对话的Id
	 */
	public void sendInteractId(String id)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(id);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.C_INTERACT, baos.toByteArray());

		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/** 发送采集草木或金石 指令 */
	public void sendLearnCollectionInofs(String temp)
	{
		if (isLockNetwork()) {
			return;
		}

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(temp);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LEARN_COLLECTION_OK,
					baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}

	}

	/** 发送遗忘采集 指令 */
	public void sendForgetCollectionInofs(String temp)
	{
		if (isLockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(temp);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FORGET_COLLECTION_OK,
					baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}

	}

	/***************************************
	 * 玩家属性
	 ***************************************/
	/**
	 * 获得玩家属性 long guid 所需要查看的玩家Id
	 */
	public void sendAttInfos(long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0,
					GameProtocol.CS_ATT_OTHER, baos.toByteArray());
			// if (guid == GameManager.getInstance().m_role.m_gameID) {// 自己
			// GameManager.getInstance().getConnection().sendMessage(0,
			// GameProtocol.CS_ATT, baos.toByteArray());
			// } else {// 其他人
			// GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY,
			// 0, GameProtocol.CS_ATT_OTHER, baos.toByteArray());
			// }
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/***************************************
	 * 攻略
	 ***************************************/
	public void sendGonglue()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GONGLUE, baos.toByteArray());
		}
		catch (Exception e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/** 一键任务 */
	public void sendOneKeyTask()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().m_role.stopAutoHangUp();
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ONT_TASK, baos.toByteArray());
		}
		catch (Exception e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/***************************************
	 * 修理道具
	 ***************************************/
	/**
	 * 修理装备背包中的道具
	 */
	public void sendNpcFixAllEquip()
	{
		//zuobi 挂机
		if(!ActorRole.m_guaji ){
			if (isLockNetwork()) {
				return;
			}
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(1);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.SC_NPC_FIX_EQUIPS, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 修理角色背包中的道具
	 */
	public void sendNpcFixAllBag()
	{
		if (isLockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.SC_NPC_FIX_ALL, baos.toByteArray());
		}
		catch (Exception e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 点击购买道具
	 *
	 * @param key
	 * @param num
	 */
	public void sendNpcShopBuy(byte moneyType, String key, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(moneyType);
			dos.writeUTF(key);
			dos.writeInt(num);// 定义当前NpcId
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.SC_NPC_SHOP_BUY, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 贩卖道具
	 *
	 * @param layer
	 * @param index
	 * @param num
	 */
	public void sendNpcShopSail(byte layer, int index, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			dos.writeByte(layer);
			dos.writeInt(index);// 定义当前NpcId
			dos.writeInt(num);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.SC_NPC_SHOP_SAIL, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	// //////////////////////背包////////////////////////////
	/**
	 * 请求道具数据 某一层的所有信息
	 */
	public void sendActorItemInfos(byte type)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_INFOS;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/** 自动吃药 */
	public void sendAutoEat(byte type){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_AUTO_EAT, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 使用某背包格子道具
	 *
	 * @param index_item
	 */
	public void sendActorItemUse(byte type, int index_item)
	{
		// Tools.debugPrintln("使用道具 sendActorItemUse type = " + type +
		// " index = " + index_item);
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeInt(index_item);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_USE;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 销毁道具
	 *
	 * @param layer
	 * @param index_item
	 * @param num
	 */
	public void sendActorItemDestroy(byte layer, int index_item, int num)
	{
		// Tools.debugPrintln("销毁道具 sendActorItemDestroy layer = " + layer +
		// " index = " + index_item + " num = " + num);
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(index_item);
			dos.writeInt(num);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_DESTORY;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 拆分道具
	 *
	 * @param layer
	 * @param index_item
	 * @param num
	 */
	public void sendActorItemDisintegrate(byte layer, int index_item, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(index_item);
			dos.writeInt(num);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_DISINTEGRATE;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 移动道具
	 *
	 * @param layer
	 * @param srcIndex
	 * @param destIndex
	 */
	public void sendActorItemMove(byte layer, int srcIndex, int destIndex)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(srcIndex);
			dos.writeInt(destIndex);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_MOVE;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 装备道具
	 *
	 * @param layer
	 * @param index_item
	 */
	public void sendActorItemEquip(byte layer, int index_item)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(index_item);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_EQUIP;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 卸载道具（从装备栏卸载到背包栏）
	 *
	 * @param layer
	 * @param index_item
	 */
	public void sendActorItemUninstall(byte layer, int index_item)
	{
		Tools.debugPrintln("卸载道具 sendActorItemUninstall layer = " + layer + " index = " + index_item);
		if (lockNetwork()) {
			Tools.debugPrintln("网络锁定，不能发出卸载道具信息");
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(index_item);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_UNINSTALL;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 查看道具详情In Npc shop
	 */
	public void sendActorItemDetail(String key)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(key);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_DETAIL_NPCSHOP;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 查看道具详情,装备对比
	 *
	 * @param layer
	 * @param index_item
	 */
	public void sendActorItemDetail(long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_DETAIL;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 专为拍卖 写的道具详情
	 * @param guid
	 */
	public void sendActorItemDetailForAuction(long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_DETAIL_AUCTION;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendOtherRoleActorItemDetail(long roleId, long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(roleId);
			dos.writeLong(guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_DETAIL_OTHER;
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 整理道具
	 *
	 * @param layer
	 * @param index_item
	 */
	public void sendActorItemTrim(byte layer)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_TRIM;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 扩容背包
	 *
	 * @param layer
	 */
	public void sendActorItemKuorong(byte layer)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_KUORONG;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendActorItemJieBang(ActorItem item)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(item.m_guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_JIEBANG;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendActorItemChakanchengpin(ActorItem item)
	{
//		if (lockNetwork()) {
//			return;
//		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte((byte)0);
			dos.writeLong(item.m_guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_CHAKANCHENGPIN;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendActorItemChakancailiao(ActorItem item)
	{
//		if (lockNetwork()) {
//			return;
//		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte((byte)1);
			dos.writeLong(item.m_guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_CHAKANCAILIAO;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 背包开启数目
	 *
	 * @param layer
	 */
	public void sendActorItemNumOpen(byte layer)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_NUM_OPEN;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 合成
	 */
	public void sendActorItemHecheng(int index_actor, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(index_actor);
			dos.writeInt(num);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_BAOSHI_HECHENG;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 镶嵌
	 */
	public void sendActorItemXiangqian(byte layer, int index_jewel, int index_good)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(index_jewel);
			dos.writeInt(index_good);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_BAOSHI_XIANGQIAN;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 提取
	 *
	 * @param layer
	 * @param m_index_dongfu_peifang
	 * @param color
	 * @param colorIndex
	 */
	public void sendActorItemTiqu(byte layer, int index_equip, byte color, int colorIndex)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(layer);
			dos.writeInt(index_equip);
			dos.writeByte(color);
			dos.writeInt(colorIndex);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_NIZI_TIQU;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 普通提取宝石
	 *
	 * @param layer
	 * @param m_index_dongfu_peifang
	 * @param color
	 * @param colorIndex
	 */
	public void sendActorItemNorTiqu(byte layer, int index_equip)
	{
		sendActorItemTiqu(layer, index_equip, (byte) 0, 0);
	}

	public void sendActorItemQianghua(byte type, long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_QIANGHUA;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 新强化界面
	 * @param type
	 * @param guid
	 */
	public void sendActorItemQianghuaNew(byte type, long guid, byte isUseQianhuafu, String key, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(guid);
			dos.writeByte(isUseQianhuafu);
			dos.writeUTF(key);
			dos.writeInt(num);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_QIANGHUA_NEW;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendActorItemQianghua(long id_dest, long id_src)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id_dest);
			dos.writeLong(id_src);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_QIANGHUA_SPEC;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendActorItemQianghuaInfo(byte type, long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_QIANGHUA_INFOS;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 新强化界面
	 * @param type
	 * @param guid
	 */
	public void sendActorItemQianghuaInfoNew(byte type, long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type);
			dos.writeLong(guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_QIANGHUA_INFOS_NEW;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 2012-4-16 下午03:24:42 venizeng
	 *
	 * @param equip
	 */
	public void sendActorItemResolve(ActorItemEquip equip)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(equip.m_guid);
			int gameProtocolType = GameProtocol.CS_ACTORITEM_RESOLVE;
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/************* 交易 **************/
	public void sendDealRequest(long id_B)
	{
		if (id_B == GameManager.getInstance().m_role.m_gameID) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "不能和自己交易");
			return;
		}
		// if (lockNetwork()) {//不管是否都发布此消息
		// Tools.debugPrintln("网络被锁定，不能发送与玩家交易指令");
		// return;
		// }
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id_B);
			int gameProtocolType = GameProtocol.CS_DEAL_REQUEST;// 请交交易(玩家A向server发交易请求/server向A发起交易请求响应)
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {

		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	// 0 成功，1失败
	public void sendDealResponse(byte response)
	{
		// if (lockNetwork()) {
		// return;
		// }
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(response);
			int gameProtocolType = GameProtocol.CS_DEAL_RESPONESE;// B to
			// Server响应交易连接请求，Server
			// to B 发送响应
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendDealLayupGoods(int index)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(index);
			int gameProtocolType = GameProtocol.CS_DEAL_GOODS_LAYUP_SELF;// A/B将背包数据放到交易栏，server将A/B
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendDealLaydownGoods(int index_deal)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(index_deal);
			int gameProtocolType = GameProtocol.CS_DEAL_GOODS_LAYDOWN_SELF;// A/B将交易栏放到背包，server将A/B
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendDealLayupMoney(long money)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(money);
			int gameProtocolType = GameProtocol.CS_DEAL_MONEY_SELF;// 放置金钱到交易处
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendDealConfig()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DEAL_CONFIG, baos.toByteArray());
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendDealCancel()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_DEAL_CANCEL, baos.toByteArray());
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**** 新邮件 *****/

	/**
	 * 发送邮件
	 */
	public void sendMail(String name, String title, String content, long money, int[] actorItemIndexs)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			if (name == null) {
				name = "";
			}
			dos.writeUTF(name);
			if (title == null) {
				title = "";
			}
			dos.writeUTF(title);
			if (content == null) {
				content = "";
			}
			dos.writeUTF(content);
			dos.writeLong(money);
			if (actorItemIndexs == null) {
				dos.writeByte((byte) 0);
			}
			else {
				dos.writeByte((byte) actorItemIndexs.length);
				for (int i = 0; i < actorItemIndexs.length; i++) {
					dos.writeInt(actorItemIndexs[i]);
				}
			}
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_MAIL_SENDMAIL, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送家族邮件
	 */
	public void sendMailFamily(String title, String content)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			title = title == null ? "" : title;
			content = content == null ? "" : content;
			dos.writeUTF(title);
			dos.writeUTF(content);
			int gameProtocolType = GameProtocol.C_MAIL_FAMILY;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendMailList(byte mailType, short pageIndex, int rowRum)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(mailType);
			dos.writeShort(pageIndex);
			dos.writeShort((short) rowRum);// 兼容
			int gameProtocolType = GameProtocol.C_MAIL_MAILLIST;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * CLT 发给UN的邮件详细
	 *
	 * @param mailId
	 */
	public void sendMailDetail(long mailId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(mailId);
			int gameProtocolType = GameProtocol.C_MAIL_MAILDETAIL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	// 删除邮件
	public void sendMailDelete(long[] mailIds)
	{
		if (isNetLocked()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int num = mailIds.length;
			dos.writeInt(num);
			for (int i = 0; i < num; i++) {
				dos.writeLong(mailIds[i]);
			}
			int gameProtocolType = GameProtocol.C_MAILLIST_DELETE;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	// 收藏邮件指令
	public void sendMailCollectMail(long[] mailIds)
	{
		if (isNetLocked()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int num = mailIds.length;
			dos.writeInt(num);
			for (int i = 0; i < num; i++) {
				dos.writeLong(mailIds[i]);
			}
			int gameProtocolType = GameProtocol.C_MAILLIST_COLLECT_MAIL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	public void sendMailRecvAcc(long mMailId, int numMail)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(mMailId);
			dos.writeInt(numMail);
			int gameProtocolType = GameProtocol.CS_MAIL_ACC;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/******
	 * 重新选择角色
	 */
	public void sendReSel()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int gameProtocolType = GameProtocol.C_USER_RESEL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_GATEWAY, 0, gameProtocolType,
					baos.toByteArray());
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/****************/
	// 拍卖
	/****************/

	public void sendAuctionSearchClose()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int gameProtocolType = GameProtocol.C_AUCTION_SEARCH_CLOSE;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendAuctionReSearchSelf(String name)
	{
		sendAuctionSearch(0, 0, UIAuctionList.MAXROW_ITEMS, UIAuctionSearch.ORDER_MONEY_ASC,0, 100, 100, 0, 0, 100, 100,name, "") ;
	}

	/**
	 * 搜索拍卖道具
	 */
	public void sendAuctionSearch(int operType, int page, int num_page_server,byte order, int actorItemtype, int actorItemSubType,
			int rare, int minLevel, int maxLevel,
			int career, int pos,String sailerName,String goodName)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(operType);
			switch (operType) {
				case 0:
					dos.writeByte((byte) page);
					dos.writeByte((byte) num_page_server);
					dos.writeByte(order);
					dos.writeByte((byte) actorItemtype);
					dos.writeByte((byte) actorItemSubType);
					dos.writeByte((byte) rare);
					dos.writeInt(minLevel);
					if (maxLevel < minLevel) {
						maxLevel = minLevel ;
					}
					dos.writeInt(maxLevel);
					dos.writeByte((byte) career);
					dos.writeByte((byte) pos);
					dos.writeUTF(sailerName);
					dos.writeUTF(goodName);
					break;
				case 1:
					dos.writeByte((byte)page);
					dos.writeByte((byte)num_page_server);
					break;
				case 2:
					dos.writeByte((byte) page);
					dos.writeByte((byte) num_page_server);
					dos.writeByte(order);
					break;
			}
			int gameProtocolType = GameProtocol.C_AUCTION_SEARCH;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 拍卖项详情
	 *
	 * @param sailId
	 */
	public void sendAuctionDetail(long sailId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(sailId);
			int gameProtocolType = GameProtocol.C_AUCTION_DETAIL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 一口价
	 *
	 * @param sailId
	 * @param money
	 */
	public void sendAuctionYikou(long sailId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(sailId);
			int gameProtocolType = GameProtocol.C_AUCTION_YIKOUJIA;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 撤消拍卖道具
	 *
	 * @param sailId
	 */
	public void sendAuctionCancel(long sailId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(sailId);
			int gameProtocolType = GameProtocol.C_AUCTION_CANCEL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, gameProtocolType,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 拍卖道具
	 *
	 * @param index
	 * @param num
	 * @param jinpai
	 * @param valueYikou
	 */
	public void sendAuctionSail(int index, int num, long jinpai, long valueYikou)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(index);
			dos.writeInt(num);
			dos.writeLong(jinpai);
			dos.writeLong(valueYikou);
			int gameProtocolType = GameProtocol.CS_AUCTION_SAIL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendAuctionOpenSail()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int gameProtocolType = GameProtocol.CS_AUCTION_OPEN_SAIL;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/****************/
	// 宠物
	/****************/

	// 查看宠物背包道具
	public void sendPetLookup(int petId, int petbagId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(petId);
			dos.writeInt(petbagId);
			int gameProtocolType = GameProtocol.C_PET_LOOKUP_GOODS;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 销毁宠物背包道具
	public void sendPetDestroy(int petId, int petbagId, int num)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(petId);
			dos.writeInt(petbagId);
			dos.writeInt(num);
			int gameProtocolType = GameProtocol.C_PET_DESTORY_GOODS;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 宠物背包道具转移到角色背包
	public void sendPetMove(int petId, int petbagId, byte type)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(petId);
			dos.writeInt(petbagId);
			dos.writeByte(type);
			int gameProtocolType = GameProtocol.C_PET_MOVE;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 查看宠物列表
	public void sendPetList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int gameProtocolType = GameProtocol.CS_PET_LIST;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 丢弃宠物
	public void sendPetAbandon(int petId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(petId);
			int gameProtocolType = GameProtocol.C_PET_ABANDON;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 更换宠物
	public void sendPetChange(int petId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(petId);
			int gameProtocolType = GameProtocol.C_PET_CHANGE;// 暂定的协议类型
			GameManager.getInstance().getConnection().sendMessage(0, gameProtocolType, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// //////////////////////////////////////////////////////////////////////////
	// ////设置相关
	/**
	 * 设置快捷键
	 */
	public void sendInitShortCut()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_INIT_SHORTCUT, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 设置快捷键
	 *
	 * @param shortcut
	 */
	public void sendSetShortCut(long[][][] shortcut)
	{
		Tools.debugPrintln("sendSetShortCut 设置快捷键");
		int num = 0;
		for (int i = 0; i < shortcut.length; i++) {
			for (int j = 0; j < shortcut[i].length; j++) {
				if (isShortcutLegal(shortcut[i][j])) {
					num++;
				}
			}
		}
		int[] indexs = new int[num];
		long[] ids = new long[num];
		int index = 0;
		int num_index = 0;
		for (int i = 0; i < shortcut.length; i++) {
			for (int j = 0; j < shortcut[i].length; j++) {
				if (isShortcutLegal(shortcut[i][j])) {
					indexs[index] = num_index;
					ids[index] = shortcut[i][j][1];
					index++;
				}
				num_index++;
			}
		}
		sendSetShortCut(num, indexs, ids);
	}

	/**
	 * 设置快捷键
	 */
	private void sendSetShortCut(int num, int[] indexs, long[] ids)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(num);
			for (int i = 0; i < num; i++) {
				dos.writeInt(indexs[i]);
				dos.writeLong(ids[i]);
			}

			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SET_SHORTCUT, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 快捷栏选项是否合法
	private boolean isShortcutLegal(long[] temp)
	{
		if (temp[0] == AbstractGameActor.ACTION_TYPE_NONE) {
			return false;
		}
		return true;
	}

	// /**
	// * 当技能修改时候同时需发送快捷键的修改
	// *
	// * @param shortcut
	// */
	// public void sendSetShortcutWhileSkill(long[][][] shortcut)
	// {
	// int num = 0;
	// for (int i = 0; i < shortcut.length; i++) {
	// for (int j = 0; j < shortcut[i].length; j++) {
	// if (shortcut[i][j][0] != AbstractGameActor.ACTION_TYPE_NONE) {
	// num++;
	// }
	// }
	// }
	// int[] indexs = new int[num];
	// long[] ids = new long[num];
	// int index = 0;
	// int num_index = 0;// 索引数目
	// // Tools.debugPrintln("发送快捷栏数据，当技能修改时");
	// for (int i = 0; i < shortcut.length; i++) {
	// for (int j = 0; j < shortcut[i].length; j++) {
	// if (shortcut[i][j][0] != AbstractGameActor.ACTION_TYPE_NONE) {
	// indexs[index] = num_index;
	// ids[index] = shortcut[i][j][1];
	// index++;
	// }
	// num_index++;
	// }
	// }
	// sendSetShortcutWhileSkill(indexs, ids);
	// }

	// /**
	// * 当技能修改的时候修改当前快捷栏
	// */
	// public void sendSetShortcutWhileSkill(int[] indexs, long[] ids)
	// {
	// // if (lockNetwork()) {
	// // return;
	// // }
	// ByteArrayOutputStream baos = new ByteArrayOutputStream();
	// DataOutputStream dos = new DataOutputStream(baos);
	// try {
	// dos.writeInt(indexs.length);
	// for (int i = 0; i < indexs.length; i++) {
	// dos.writeInt(indexs[i]);
	// dos.writeLong(ids[i]);
	// }
	// GameManager
	// .getInstance()
	// .getConnection()
	// .sendMessage(0, GameProtocol.CS_SET_SHORTCUT_SKILL,
	// baos.toByteArray());
	// dos.close();
	// dos = null;
	// baos.close();
	// baos = null;
	// }
	// catch (IOException e) {
	// e.printStackTrace();
	// }
	// }

	public void sendInitMarco()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_INIT_MARCO, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 设置宏
	 *
	 * @param items
	 * @return
	 */
	public boolean sendSetMarco(Object[][] items)
	{
		if (lockNetwork()) {
			return true;
		}
		// Tools.debugPrintln("发送设置宏信息");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte((byte) items.length);
			for (int i = 0; i < items.length; i++) {// 宏
				dos.writeByte((byte) items[i].length);
				for (int j = 0; j < items[i].length; j++) {// 动作
					byte type = 0;
					long id = 0;
					if (items[i] == null) {
						type = 0;
					}
					else {
						if (items[i][j] instanceof RoleCombatSkill) {
							type = AbstractGameActor.ACTION_TYPE_SKILL;
							RoleCombatSkill skill = (RoleCombatSkill) items[i][j];
							id = skill.m_id;
						}
						else if (items[i][j] instanceof ActorItem) {
							type = AbstractGameActor.ACTION_TYPE_ITEM;
							ActorItem actorItem = (ActorItem) items[i][j];
							id = actorItem.m_guid;
						}
						else if (items[i][j] instanceof MenuFunction) {
							type = AbstractGameActor.ACTION_TYPE_FUNCTION;
							MenuFunction funcation = (MenuFunction) items[i][j];
							id = funcation.getId();
						}
						else {

						}
					}
					dos.writeByte(type);// 类型
					if (type == 0) {
						continue;
					}
					dos.writeLong(id);// id
				}
			}
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SET_MARCO, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
		return false;
	}

	/**
	 * 当技能发生修改， 客户端修改宏，避免同步导致的一大堆问题
	 */
	public void sendMarOnSkillChanged()
	{
		ActorRole role = GameManager.getInstance().m_role;
		GameMacro[] gameMacros = role.m_game_macro;
		if (gameMacros == null) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(gameMacros.length);// 宏的数目
			for (int i = 0; i < gameMacros.length; i++) {
				GameMacro marco = gameMacros[i];
				long[][] actions = marco.m_actionId;
				dos.writeByte(actions.length);// 宏中技能数目
				for (int j = 0; j < actions.length; j++) {
					dos.writeByte((byte) actions[j][GameMacro.MACRO_INDEX_TYPE]);// 宏中技能的相应类型
					if (actions[j][GameMacro.MACRO_INDEX_TYPE] == 0) {
						continue;
					}
					dos.writeLong(actions[j][GameMacro.MACRO_INDEX_ID]);// 宏中技能的相应ID
				}
			}
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.C_SET_MARCO_SKILLCHANGED,
					baos.toByteArray());
		}
		catch (IOException e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	// //////////////////////////////////////////////////////////////////////////
	// // 聊天相关

	/**
	 * 屏蔽聊天栏
	 */
	public void sendChatPingBi(byte type)
	{
		sendChatPindaoOperation(0, type);
	}

	/**
	 * 屏蔽聊天栏
	 */
	public void sendChatOpen(byte type)
	{
		sendChatPindaoOperation(1, type);
	}

	/**
	 * 屏蔽聊天栏
	 */
	private void sendChatPindaoOperation(int operation, byte type)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte((byte) operation);
			dos.writeByte(type);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE,0, GameProtocol.C_CHATITEM_PINDAO_OPERATION,
					baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 获取玩家聊天信息
	 */
	public void sendChatItemList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		//
		try {
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_CHATITEM_INFOS, baos.toByteArray());
		}
		catch (Exception e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送给地图的聊天信息 2012-3-9 上午10:42:45 venizeng
	 *
	 * @param content
	 */
	public void sendChatQu(String content)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.C_CHAT_QU, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送给家族的 2012-3-9 上午10:42:45 venizeng
	 *
	 * @param content
	 */
	public void sendChatFamily(String content)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.C_CHAT_FAMILY, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送给家族的 2012-3-9 上午10:42:45 venizeng
	 *
	 * @param content
	 */
	public void sendChatRealm(String content)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.C_CHAT_REAML, baos.toByteArray());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送给队伍的 2012-3-9 上午10:42:57 venizeng
	 *
	 * @param content
	 */
	public void sendChatWorld(String content)
	{
		// Tools.debugPrintln("发送世界喊话");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.C_CHAT_WORLD, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送给队伍的 2012-3-9 上午10:42:57 venizeng
	 *
	 * @param content
	 */
	public void sendChatWorldBySpeaker(long id, String content)
	{
		// Tools.debugPrintln("发送世界喊话");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(content);
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.C_CHAT_SERVER, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 发送给队伍的 2012-3-9 上午10:42:57 venizeng
	 *
	 * @param content
	 */
	public void sendChatTeam(String content)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.C_CHAT_TEAM, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 提交玩家聊天信息
	 */
	public void sendChatItemCommitPrivate(long recverId, String content)
	{
		// Tools.debugPrintln("提交玩家聊天信息");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(recverId);
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_CHATITEM_COMMIT_ID, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 提交玩家聊天信息
	 */
	public void sendChatItemCommitPrivate(String name_recver, String content)
	{
		// Tools.debugPrintln("提交玩家聊天信息");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(name_recver);
			dos.writeUTF(content);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_CHATITEM_COMMIT_NAME, baos.toByteArray());
		}
		catch (IOException e) {
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 获得玩家聊天信息最大条数
	 */
	public void sendChatItemMaxNum()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CHATITEM_MAXNUM,
					baos.toByteArray());
		}
		catch (Exception e) {

		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	// ///通缉令相关
	/**
	 * 请求查看选中的通缉令信息
	 * */
	public void sendWantedSee(long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_WANTED_SEE, baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_WANTED_SEE);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 在通缉令中请求添加仇敌
	 * */
	public void sendWantedAddEnemy(long guid, String name)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_WANTED_ADDENEMY, baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_WANTED_ADDENEMY);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/** 请求系统公告 */
	public void sendAnnouncement()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAME_ANNOUNCEMENT,
					baos.toByteArray());
			Tools.debugPrintln("发送请求系统公告信息 : " + GameProtocol.CS_GAME_ANNOUNCEMENT);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/** 请求单元公告内容 */
	public void sendGameNoticeInfo(byte index)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(index);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_GAME_NOTICE_INFO,
					baos.toByteArray());
			Tools.debugPrintln("发送请求单元公告信息 : " + GameProtocol.CS_GAME_NOTICE_INFO);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 通缉令请求查看目标位置
	 * */
	public void sendChecTargetPosition(long guid, String name)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			dos.writeUTF(name);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_WANTED_TARGETPOSITION, baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_WANTED_TARGETPOSITION);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 通缉令请求排序和翻页
	 *
	 * @param byte 排序类型
	 * @param short 请求页数
	 * @param short 每页显示条数
	 * */
	public void sendWantedFilp(byte sortType, short page, short line)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(sortType);
			dos.writeShort(page);
			dos.writeShort(line);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_WANTED_FILP, baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_WANTED_FILP);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 通缉令我的发布请求与翻页
	 *
	 * @param short 请求页数
	 * @param short 每页显示条数
	 * */
	public void sendWantedMyPublishFilp(short page, short line)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(page);
			dos.writeShort(line);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0,
					GameProtocol.CS_WANTED_MYPUBLISH, baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_WANTED_MYPUBLISH);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 接通缉令
	 * */
	public void sendWantedRecv(long guid)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_WANTED_RECV, baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_WANTED_RECV);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// //////////////////////////////////////////////////////////////////////////
	// // 战斗相关
	/**
	 * 初始化角色技能列表 ID：5200
	 */
	public void sendCombatSkillList()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_COMBAT_SKILL_LIST,
					baos.toByteArray());
			Tools.debugPrintln("发送技能信息 : " + GameProtocol.CS_COMBAT_SKILL_LIST);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 学习技能 ID：5201
	 *
	 * @param skillId
	 */
	public void sendLearnCombatSkill(int skillId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(skillId);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_LEARN_COMBAT_SKILL,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 洗掉技能 ID：5202
	 *
	 * @param skillId
	 */
	public void sendAbolishCombatSkill(int skillId)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(skillId);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ABOLISH_COMBAT_SKILL,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 洗掉全部技能 ID：5203
	 *
	 * @param skillId
	 */
	public void sendAbolishAllCombatSkill()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ABOLISH_ALL_COMBAT_SKILL,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 施放技能 ID:5204
	 *
	 * @param skillId
	 * @param targetId
	 */
	public void sendCastSkill(short skillId, byte targetType, long targetId)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(skillId);
			dos.writeByte(targetType);
			dos.writeLong(targetId);
			long time = System.currentTimeMillis() + GameManager.s_worldTimeDelay;
			// Date data = new Date(time);
			// System.out.println("发送战斗指令时间：" + data.toString());
			dos.writeLong(time);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CAST_SKILL, baos.toByteArray());
			Tools.debugPrintln("发送5204指令!" + skillId);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 位移验证 指令号 5220
	 *
	 * @param skillId
	 * @param targetId
	 */
	public void sendCastSkillMove(short skillId, long targetId, int x, int y)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(skillId);
			dos.writeLong(targetId);
			dos.writeInt(x);
			dos.writeInt(y);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CAST_SKILL_MOVE,
					baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_CAST_SKILL_MOVE + "指令!" + skillId);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 施法取消 ID：5207
	 */
	public void sendCastCancel()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CAST_CANCEL, baos.toByteArray());
			Tools.debugPrintln("发送5207指令!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendSkillDetail(short id_skill)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(id_skill);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.SC_SKILL_DETAIL, baos.toByteArray());
			Tools.debugPrintln("发送5214指令!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 打开或关闭符咒开关
	public void sendControlSpell(byte _switch)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(_switch);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CONTROL_SPELL, baos.toByteArray());
			Tools.debugPrintln("发送指令730");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// // 战斗相关
	// //////////////////////////////////////////////////////////////////////////

	// //////////////////////////////////////////////////////////////////////////
	// // 资源相关
	public void sendRequestResource(ResHead res)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(1);
			dos.writeByte(res.m_type);
			dos.writeUTF(res.m_url);
			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_RES, 0,
					GameProtocol.CS_REQUEST_RESOURCE, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendRequestResource(Vector res)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			int length = res.size();
			dos.writeShort(length);
			ResHead head;
			for (int i = 0; i < length; i++) {
				head = (ResHead) res.elementAt(i);
				dos.writeByte(head.m_type);
				dos.writeUTF(head.m_url);
				Tools.debugPrintln("请求资源url:" + head.m_url);
			}

			GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_RES, 0,
					GameProtocol.CS_REQUEST_RESOURCE, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	// // 资源相关
	// //////////////////////////////////////////////////////////////////////////

	/**
	 * 发送拾取道具
	 *
	 * @param id
	 */
	public void sendPickUpItem(long id)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(id);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_PICKUP_ITEM, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送结束动画 559
	 */
	public void sendEndTrailer()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_END_TRAILER, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 设置角色坐标（脚本动画中用）
	 *
	 * @param x
	 * @param y
	 */
	public void sendSetPosition(int x, int y)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(x);
			dos.writeShort(y);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCRIPT_SET_POSITION,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 切换场景（脚本动画中用）
	 *
	 * @param sceneKey
	 * @param x
	 * @param y
	 */
	public void sendSwitchScene(String sceneKey, int x, int y)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(sceneKey);
			dos.writeShort(x);
			dos.writeShort(y);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_SCRIPT_SWITCH_SCENE,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 脱离卡死，服务器不回推 2012-3-27 下午03:35:36 venizeng
	 */
	public void sendUserTuoli()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.S_USER_TUOLI, baos.toByteArray());
		}
		catch (Exception e) {
			// e.printStackTrace();
		}
		finally {
			try {
				dos.close();
			}
			catch (IOException e) {
			}
			dos = null;
			try {
				baos.close();
			}
			catch (IOException e) {
			}
			baos = null;
		}
	}

	/**
	 * 请求打开每日任务界面
	 */
	public void sendOpenActivity()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_OPEN_ACTIVITY_WINDOW,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_OPEN_ACTIVITY_WINDOW);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求打开活动中副本活动界面
	 * */
	public void sendOpenFBActivity()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_OPEN_FB_ACTIVITY_WINDOW,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_OPEN_FB_ACTIVITY_WINDOW);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendMustJion()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_FB_MUST_JION, baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_FB_MUST_JION);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求立即完成任务
	 */
	public void sendActivityCompleteTask()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ACTIVITY_COMPLETE_TASK,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_ACTIVITY_COMPLETE_TASK);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 确认立即完成任务
	 */
	public void sendActivityCompleteTaskOk(byte moneyType)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.write(moneyType);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ACTIVITY_COMPLETE_TASK_OK,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_ACTIVITY_COMPLETE_TASK_OK);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求更换任务
	 */
	public void sendActivityBuyTask()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ACTIVITY_BUY_TASK,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_ACTIVITY_BUY_TASK);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 确认购买任务
	 */
	public void sendActivityBuyTaskOk(byte moneyType)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(moneyType);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_ACTIVITY_BUY_TASK_OK,
					baos.toByteArray());
			Tools.debugPrintln("发送指令" + GameProtocol.CS_ACTIVITY_BUY_TASK_OK);
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}


	/**
	 * 获取排行列表
	 *
	 * @param currterPage
	 * @param number
	 */
	public void sendRankingList(byte type, short currterPage, short number)
	{

		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeShort(currterPage);
			dos.writeShort(number);
			int value = -1;
			switch (type) {
				case 1:// 家族排行
					value = GameProtocol.CS_RANKINGLIST_FAMILY;
					break;
				case 2:// 等级排行
					value = GameProtocol.CS_RANKINGLIST_LIVEL;
					break;
				case 3:// 财富排行
					value = GameProtocol.CS_RANKINGLIST_WEALTH;
					break;
				case 4:// 击杀排行
					value = GameProtocol.CS_RANKINGLIST_KILL;
					break;
				case 5:// 贡献排行
					value = GameProtocol.CS_RANKINGLIST_CONTRIBUTION;
					break;
				case 6:// 战功排行
					value = GameProtocol.CS_RANKINGLIST_MILITARY_EXPLOITS;
					break;
				case 7:// 采集排行
					value = GameProtocol.CS_RANKINGLIST_COLLECTION;
					break;
				case 8:// 攻伐排行
					value = GameProtocol.CS_RANKINGLIST_ATTACK;
					break;
				case 9:// 社交排行
					value = GameProtocol.CS_RANKINGLIST_SOCIAL_CONTACT;
					break;
			}
			if (value != -1) {
				GameManager.getInstance().getConnection().sendMessage(BaseConnection.DEST_UNIVERSE, 0, value,
						baos.toByteArray());
			}
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendBuyItemInMulMoney(String actoritemKey, byte type_money, long price, int mBuyNum)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(actoritemKey);
			dos.writeByte(type_money);
			dos.writeLong(price);
			dos.writeInt(mBuyNum);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_BUY_ITEM_WITH_MUL_MONEY,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

    public void sendGetBuyItemInMulMoney(String actoritemKey, long actor_ID) {
        if (lockNetwork()) {
            return;
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        try {
            // dos.writeByte(type_money);
            dos.writeLong(actor_ID);
            dos.writeUTF(actoritemKey);
            // dos.writeInt(mBuyNum);
            GameManager
                    .getInstance()
                    .getConnection()
                    .sendMessage(BaseConnection.DEST_GATEWAY, 0 ,
                            GameProtocol.S_RMB_GET_ITEM_UP, baos.toByteArray());
            dos.close();
            dos = null;
            baos.close();
            baos = null;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

	/**
	 * 赠送道具给某人 2012-5-3 下午07:15:00 venizeng
	 *
	 * @param id_actoritem
	 * @param type_money
	 * @param price_rmb
	 * @param mBuyNum
	 * @param mNameRecver
	 */
	public void sendItemToSbInMulMoney(String itemKey, byte type_money, long price_rmb, int mBuyNum, long id,
			String mNameRecver)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(itemKey);
			dos.writeByte(type_money);
			dos.writeLong(price_rmb);
			dos.writeInt(mBuyNum);
			dos.writeLong(id);
			dos.writeUTF(mNameRecver);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_PRESENT_ITEM_WITH_MUL_MONEY,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 金钱购买功能实现 2012-5-3 下午07:07:20 venizeng
	 *
	 * @param id_actoritem
	 * @param type_money
	 * @param price_rmb
	 * @param mBuyNum
	 * @param mNameRecver
	 */
	public void sendBuyFunWithMoney(byte type_money, long price, int operType)
	{
		if (isLockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeByte(type_money);
			dos.writeLong(price);
			dos.writeInt(operType);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_BUY_FUN_WITH_MUL_MONEY,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 2012-4-25 下午07:10:26 venizeng
	 */
	public void sendOpenMarket()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_OPEN_MARKET, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 2012-4-25 下午07:10:26 venizeng
	 */
	public void sendOpenChongzhi()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_OPEN_CHONGZHI, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendChongzhiMianer()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CHONGZHI_MIANER,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendChongzhi(String yunyingshang, String mianer, String id, String pass)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			Tools.debugPrintln("进充值");
			dos.writeUTF(yunyingshang);
			dos.writeUTF(mianer);
			dos.writeUTF(id);
			dos.writeUTF(pass);
			Tools.debugPrintln("充值了=" + GameProtocol.CS_CHONGZHI_CONFIG);
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_CHONGZHI_CONFIG,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看充值记录
	 */
	public void sendChongzhiRecord()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.write(0);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_QUERY_CHONGZHI, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void sendYuanbaoyuer()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.write(1);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_QUERY_CHONGZHI, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查看充值记录
	 */
	public void sendYuanbaoConsumeRecord()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0, GameProtocol.CS_QUERY_YUANBAO_CONSUME,
					baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求装备强化消除
	 *
	 * @param id
	 * @param type
	 */
	public void sendToEquipCancel(long guid,byte type)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			dos.writeByte(type);
			Tools.debugPrintln("请求强化消除的类型："+type);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.C_TO_EQUIPCANCEL, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.C_TO_EQUIPCANCEL + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 确定装备强化消除
	 *
	 * @param id
	 * @param type
	 */
	public void sendComfirmEquipCancel(long guid,byte type)
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeLong(guid);
			dos.writeByte(type);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.C_CONFIRMATION_EQUIPCANCEL, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.C_CONFIRMATION_EQUIPCANCEL + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求打开挂机双倍界面
	 *
	 * @param id
	 */
	public void sendAutoHangUp()
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_AUTO_HANGUP, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_AUTO_HANGUP + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求打开购买挂机双倍
	 *
	 * @param id
	 */
	public void sendOpenBuyTwo()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_OPEN_BUY_TWO, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_OPEN_BUY_TWO + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 请求确定购买双倍
	 *
	 * @param id
	 */
	public void sendBuyTwo(boolean isYinpiao,int num)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);

		try {
			byte index = isYinpiao?(byte)1:(byte)0;
			dos.writeByte(index);
			dos.writeInt(num);
			GameManager.getInstance().getConnection()
					.sendMessage(0, GameProtocol.CS_BUY_TWO, baos.toByteArray());
			Tools.debugPrintln("发送" + GameProtocol.CS_BUY_TWO + "信息!");
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 打开家族商店的菜单列表
	 *
	 */
	public void sendOpenFamilyShopList()
	{
		if (lockNetwork()) {
			return;
		}
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			GameManager.getInstance().getConnection().sendMessage(0,
					GameProtocol.C_OPENLIST_FAMILYSHOP, baos.toByteArray());

			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 打开家族商店
	 *
	 */
	public void sendOpenFamilyShop(int oder,String temp)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeUTF(temp);
			GameManager.getInstance().getConnection().sendMessage(0,
					oder, baos.toByteArray());
			dos.close();
			dos = null;
			baos.close();
			baos = null;
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

}
